﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Views;
using CommunitySystem.ZhaoLuService;
using EHR.Common;
using org.in2bits.MyXls;

namespace CommunitySystem
{
    public partial class zhengShenControl_ZLGL : UserControl
    {
        private ZhaoLuService.ZhaoLuServiceClient Client1 = new ZhaoLuServiceClient();
        private ObservableCollection<ZhaoLuJiHuaModel> poi =
           new ObservableCollection<ZhaoLuJiHuaModel>();
        private ObservableCollection<ZhaoLu_DaoRuKaoShengModel> selectedempmodel =
            new ObservableCollection<ZhaoLu_DaoRuKaoShengModel>();
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient Client2 = 
            new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
        public zhengShenControl_ZLGL()
        {
            InitializeComponent();
            //for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            //{
            //    ComboBoxItem cbi = new ComboBoxItem();
            //    cbi.Content = i.ToString();
            //    cbi.Tag = i;
            //    nian.Items.Add(cbi);
            //}
            //nian.SelectedIndex = 0;
            _gridClickManagerXQ = new MouseClickManager(DGRole, 300);
            _gridClickManagerXQ.DoubleClick += new System.Windows.Input.MouseButtonEventHandler(_gridClickManagerXQ_DoubleClick);
            Client.GetDengLuJueSeCompleted += new EventHandler<EmpbasicService.GetDengLuJueSeCompletedEventArgs>(Client_GetDengLuJueSeCompleted);
            Client.GetDengLuJueSeAsync(Session.LoginUser.LoginName);
            if (TreeOfLife.ItemsSource != null) TreeOfLife.ItemsSource = null;
            Client.GetOrgForHRModelCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelCompletedEventArgs>(Client_GetOrgForHRModelCompleted);
            Client.GetOrgForHRModelAsync(0);
            Client1.GetZhaoLu_DaoRuKaoShengModelCompleted += new EventHandler<GetZhaoLu_DaoRuKaoShengModelCompletedEventArgs>(Client1_GetZhaoLu_DaoRuKaoShengModelCompleted);
            Client1.QiQuanCompleted += new EventHandler<QiQuanCompletedEventArgs>(Client1_QiQuanCompleted);
            Client1.UpdateZL_ZhengShenCompleted += new EventHandler<UpdateZL_ZhengShenCompletedEventArgs>(Client1_UpdateZL_ZhengShenCompleted);
            Client1.GetZhaoLuJiHuaModelForComCompleted += new EventHandler<GetZhaoLuJiHuaModelForComCompletedEventArgs>(Client1_GetZhaoLuJiHuaModelForComCompleted);
            Client1.GetZhaoLuJiHuaModelForComAsync();
        }
        private readonly MouseClickManager _gridClickManagerXQ;
        
        private void _gridClickManagerXQ_DoubleClick(object sender, MouseButtonEventArgs e)
        {
        }

        private string juese = "";
        void Client_GetDengLuJueSeCompleted(object sender, EmpbasicService.GetDengLuJueSeCompletedEventArgs e)
        {
            juese = e.Result;
            if (e.Result != "人事干部")
            {
                TreeOfLife.Visibility = System.Windows.Visibility.Visible;
                colLeft.Width = new GridLength(265);
                colSplit.Width = new GridLength(10);
            }
            else
            {
                TreeOfLife.Visibility = System.Windows.Visibility.Collapsed;
                colLeft.Width = new GridLength(0);
                colSplit.Width = new GridLength(0);
            }
        }
        #region 左右拖动的条
        private GridLength _lastColLeftLength;
        private GridLength _lastColRightLength;
        private void GridSpliteTo_ToLeft(object sender, EventArgs e)
        {
            //已经到最左边，直接返回
            if (colLeft.Width.Value == 0.0)
            {
                return;
            }

            //
            if (colRight.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colLeft.Width = new GridLength(0);
                colRight.Width = new GridLength(150, GridUnitType.Star);
            }
        }

        private void GridSpliteTo_ToRight(object sender, EventArgs e)
        {
            if (colRight.Width.Value == 0)
            {
                return;
            }

            if (colLeft.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colRight.Width = new GridLength(0);
                colLeft.Width = new GridLength(300, GridUnitType.Star);
            }
        }
        #endregion
        #region treeview
        void Client_GetOrgForHRModelCompleted(object sender, EmpbasicService.GetOrgForHRModelCompletedEventArgs e)
        {
            forumList.Clear();
            foreach (EmpbasicService.OrgForHRModel i in e.Result)
            {
                forumList.Add(i);
            }
            AddTreeNode("全部单位", null);
        }
        ObservableCollection<EmpbasicService.OrgForHRModel> forumList = new ObservableCollection<EmpbasicService.OrgForHRModel>();


        private void AddTreeNode(string type, TreeViewItem treeViewItem)
        {
            List<EmpbasicService.OrgForHRModel> result = (from forumInfo in forumList
                                                          where forumInfo.Type == type
                                                          select forumInfo).ToList<EmpbasicService.OrgForHRModel>();

            if (result.Count > 0)
            {
                foreach (EmpbasicService.OrgForHRModel foruminfo in result)
                {
                    TreeViewItem objTreeNode = new TreeViewItem();
                    CheckBox cb = new CheckBox();
                    cb.Content = foruminfo.Name;
                    cb.Tag = objTreeNode;
                    cb.DataContext = foruminfo;
                    //sp.Children.Add(cb);
                    cb.Click += new RoutedEventHandler(cb_Checked);
                    objTreeNode.Header = cb;
                    if ((objTreeNode.Header as CheckBox).Content.ToString() == "组织机构") objTreeNode.IsExpanded = true;
                    //添加根节点
                    if (treeViewItem == null)
                    {
                        TreeOfLife.Items.Add(objTreeNode);
                    }
                    else
                    {
                        treeViewItem.Items.Add(objTreeNode);
                    }
                    AddTreeNode(foruminfo.Name, objTreeNode);
                }
            }
        }
        void cb_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            EmpbasicService.OrgForHRModel rm = cb.DataContext as EmpbasicService.OrgForHRModel;
            if (cb.IsChecked == true)
            {
                //if (orgids != null)
                //{
                //    OrgID = Convert.ToInt32(((EmpbasicService.OrgForHRModel)cb.DataContext).ID);
                //    LoadData(OrgID);
                //    //if (OrgID != 0 && OrgID != 79 && OrgID != 80 && OrgID != 81 && OrgID != 82 && OrgID != 83 && OrgID != 84)
                //    //{

                //    //}
                //}
                //else orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                    orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                Load();
                //LoadData(ss.Substring(0, ss.Length - 1));
                //CheckParentItem(cb.Tag as TreeViewItem);
                CheckChildItem(cb.Tag as TreeViewItem);
            }
            else
            {
                if (orgids != null)
                {
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                }
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                Load();
                //LoadData(ss.Substring(0, ss.Length - 1));
                UnCheckChildItem(cb.Tag as TreeViewItem);
            }
        }
        void CheckParentItem(TreeViewItem item)
        {
            TreeViewItem tvi = item.GetParentTreeViewItem();
            if (tvi != null)
            {
                CheckBox cb = tvi.Header as CheckBox;
                cb.IsChecked = true;
                CheckParentItem(tvi);
            }
        }
        public List<string> orgids = new List<string>();
        void CheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = true;
                    if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    CheckChildItem(tvi);
                }
            }
        }
        void UnCheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = false;
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    UnCheckChildItem(tvi);
                }
            }
        }
        #endregion
        void Client1_GetZhaoLuJiHuaModelForComCompleted(object sender, GetZhaoLuJiHuaModelForComCompletedEventArgs e)
        {
            poi = e.Result;
            ObservableCollection<ZhaoLuJiHuaModel> poi1 = new ObservableCollection<ZhaoLuJiHuaModel>();
            poi1.Add(poi.Where(p => p.IsLocked == false).FirstOrDefault());
            nian.ItemsSource = poi1;
            if (poi1.Count > 0) nian.SelectedIndex = 0;
            Load();
        }
        private int tiaojian = 0;
        void gangwei_SelectionChanged1(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            {
                tiaojian = ((ZhaoLuJiHuaModel)(((ComboBox)sender).SelectedItem)).ID;
            }
        }
        public void Load()
        {
            Client2.GetOrgIDbyDengLuRenCompleted -= new EventHandler<PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs>(Client_GetOrgIDbyDengLuRenCompleted);
            Client2.GetOrgIDbyDengLuRenCompleted += new EventHandler<PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs>(Client_GetOrgIDbyDengLuRenCompleted);
            Client2.GetOrgIDbyDengLuRenAsync(Session.LoginUser.UserID);
        }
        void Client_GetOrgIDbyDengLuRenCompleted(object sender, PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs e)
        {
            string[] ss = e.Result.Split(',');
            foreach (string i in ss)
            {
                Client2.GetTypebyOrgIDCompleted -= new EventHandler<PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs>(Client_GetTypebyOrgIDCompleted);
                Client2.GetTypebyOrgIDCompleted += new EventHandler<PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs>(Client_GetTypebyOrgIDCompleted);
                Client2.GetTypebyOrgIDAsync(Convert.ToInt32(i));
            }

        }
        void Client_GetTypebyOrgIDCompleted(object sender, PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                foreach (string i in e.Result.Keys)
                {

                    //OrgID = Convert.ToInt32(e.Result[i]);
                    if (!orgids.Contains(e.Result[i].ToString()))
                        orgids.Add(e.Result[i].ToString());
                    string ss = "";
                    foreach (string ii in orgids)
                        ss += ii + ",";
                    if (string.IsNullOrEmpty(ss)) ss = "0";
                    else ss = ss.Substring(0, ss.Length - 1);
                    Client1.GetZhaoLu_DaoRuKaoShengModelAsync(tiaojian, false, 0, 0, "拟同意", "合格", "", null, "", "无",ss);

                }
            }

        }
        private ObservableCollection<ZhaoLuZhengShen_AttatchmentModel> _Attachment =
            new ObservableCollection<ZhaoLuZhengShen_AttatchmentModel>();
        void Client1_GetZhaoLu_DaoRuKaoShengModelCompleted(object sender, GetZhaoLu_DaoRuKaoShengModelCompletedEventArgs e)
        {
            _Attachment.Clear();
            DGRole.ItemsSource = null;
            if (e.Result != null && e.Result.Count > 0)
            {
                for (int i = 0; i < e.Result.Count; i++)
                {
                    e.Result[i].Sec = i + 1;
                    foreach (var item in e.Result[i].Attachment)
                    {
                        if (!_Attachment.Contains(_Attachment.Where(p => p.realname == item.realname && p.MainID == item.MainID).FirstOrDefault()))
                            _Attachment.Add(item);
                    }

                }
                DGRole.ItemsSource = e.Result;
            }
        }
        private WrapPanel dgwp = null;
        private void dgXQ_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.MouseLeftButtonUp += _gridClickManagerXQ.HandleClick;
            ZhaoLu_DaoRuKaoShengModel bindData = (ZhaoLu_DaoRuKaoShengModel)e.Row.DataContext;
            dgwp = DGRole.Columns[7].GetCellContent(e.Row).FindName("wp") as WrapPanel;

            Init(bindData.ID);
        }
        private void Init(int id)
        {
            dgwp.Children.Clear();
            HyperlinkButton hb = null;
            foreach (var item in _Attachment.Where(p => p.MainID == id).ToList())
            {
                hb = new HyperlinkButton() { Margin = new Thickness(10, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center };
                hb.MouseLeftButtonDown += new MouseButtonEventHandler(hb_MouseLeftButtonDown);
                hb.Tag = item;
                hb.Content = item.realname;
                hb.Click += new RoutedEventHandler(hb_Click);
                dgwp.Children.Add(hb);
            }
        }
        void hb_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //throw new NotImplementedException();
        }
        private List<byte> fileContent = new List<byte>();
        SaveFileDialog openFile;
        /// <summary>
        /// 附件下载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void hb_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton hbtn = sender as HyperlinkButton;

            var attach = hbtn.Tag as ZhaoLuZhengShen_AttatchmentModel;

            SilverlightMessageBoxLibrary.CustomMessage cm = new SilverlightMessageBoxLibrary.CustomMessage("确认要下载此方案吗?", SilverlightMessageBoxLibrary.CustomMessage.MessageType.Confirm, null);
            cm.Show();
            cm.OKButton.Click += (sender1, e1) =>
            {
                string extend = attach.realname.Substring(attach.realname.LastIndexOf('.'));
                 openFile = new SaveFileDialog() { Filter = string.Format("{0}|*.{0}", extend) };
                if (openFile.ShowDialog() == true)
                {
                    IsWorking.Visibility = Visibility.Visible;
                    tkbusy.BusyContent = "正在下载数据，请稍后...";

                    fileContent.Clear();
                    //Client2.DownLoadFileCompleted -= new EventHandler<PublicOfficialSelectionService.DownLoadFileCompletedEventArgs>(downLoadClient_DownLoadFileCompleted);
                    //Client2.DownLoadFileCompleted += new EventHandler<PublicOfficialSelectionService.DownLoadFileCompletedEventArgs>(downLoadClient_DownLoadFileCompleted);

                    //Client2.DownLoadFileAsync(new PublicOfficialSelectionService.DownLoadFile() { PathKey = "file", HasFinished = false, Lenght = 1600, FileName = attach.filename, StartPosition = 0 }, openFile.OpenFile());

                    CommunitySystem.JinShengService.JinShengServiceClient client = new JinShengService.JinShengServiceClient();
                    client.DownLoadFile1Completed -= new EventHandler<JinShengService.DownLoadFile1CompletedEventArgs>(client_DownLoadFile1Completed);
                    client.DownLoadFile1Completed += new EventHandler<JinShengService.DownLoadFile1CompletedEventArgs>(client_DownLoadFile1Completed);
                    client.DownLoadFile1Async(attach.filename);
                }

            };
        }

        void client_DownLoadFile1Completed(object sender, JinShengService.DownLoadFile1CompletedEventArgs e)
        {
            Stream myStream;
            if ((myStream = openFile.OpenFile()) != null)
            {
                using (BinaryWriter bw = new BinaryWriter(myStream))
                {

                    bw.Write(e.Result);
                    myStream.Dispose();
                    myStream.Close();
                    SilverlightMessageBoxLibrary.Message.InfoMessage("下载完毕!");
                    IsWorking.Visibility = Visibility.Collapsed;
                }

            }
        }
        void downLoadClient_DownLoadFileCompleted(object sender, PublicOfficialSelectionService.DownLoadFileCompletedEventArgs e)
        {
            var down = e.Result;
            fileContent.AddRange(down.Content);
            if (down.HasFinished == true)
            {
                var stream = e.UserState as Stream;
                stream.Write(fileContent.ToArray(), 0, fileContent.Count);
                stream.Dispose();
                stream.Close();

                SilverlightMessageBoxLibrary.Message.InfoMessage("下载完毕!");

                IsWorking.Visibility = Visibility.Collapsed;
            }
            else
            {
                down.StartPosition += down.Lenght;
                Client2.DownLoadFileAsync(down, e.UserState);
            }
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Data_Click(object sender, RoutedEventArgs e)
        {
          
            selectedempmodel.Clear();
            count = 0;
            if (DGRole.ItemsSource != null)
            {
                foreach (ZhaoLu_DaoRuKaoShengModel i in (ObservableCollection<ZhaoLu_DaoRuKaoShengModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count >0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一个人员进行编辑！");
                    return;
                }
                ZhengShenWindow RMWindow = new ZhengShenWindow(selectedempmodel[0].ID);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的政审情况！"); 
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            Load();
        }
        private int count = 0;
        void Client1_UpdateZL_ZhengShenCompleted(object sender, UpdateZL_ZhengShenCompletedEventArgs e)
        {
            if (count == selectedempmodel.Count)
            {
                count = count - 1;
                SilverlightMessageBoxLibrary.Message.InfoMessage("保存成功!");
                Load();
            }
        }
        private void fangqi_Click(object sender, RoutedEventArgs e)
        {
            if (DGRole.ItemsSource != null)
            {
                foreach (ZhaoLu_DaoRuKaoShengModel i in (ObservableCollection<ZhaoLu_DaoRuKaoShengModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定进行弃权操作吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ss = "";
                    string ss1 = "";
                    foreach (ZhaoLu_DaoRuKaoShengModel i in selectedempmodel)
                    {
                        if (i.ZhengShenResult == "合格") ss += i.ID.ToString() + ",";
                        if (string.IsNullOrEmpty(i.ZhengShenResult)) ss1 += i.ID.ToString() + ",";
                    }
                
                    Client1.QiQuanAsync(ss.TrimEnd(','), "录用前");
                
                    Client1.QiQuanAsync(ss1.TrimEnd(','), "政审前");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要弃权的人员！"); 
        }
        private bool can = false;
        void Client1_QiQuanCompleted(object sender, QiQuanCompletedEventArgs e)
        {
            if (can)
            {
                MessageBox.Show("弃权成功！");
                Load();
                can = false;
            }
            else can = true;
        }
        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }
        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (ZhaoLu_DaoRuKaoShengModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault());
                    }
                }
            }
        }
        private Stream ss = null;
        /// <summary>
        /// 导出 XlsDocument
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveData_Click(object sender, RoutedEventArgs e)
        {
            if (DGRole.ItemsSource != null)
            {
                foreach (ZhaoLu_DaoRuKaoShengModel i in (ObservableCollection<ZhaoLu_DaoRuKaoShengModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                var downLoad = new SaveFileDialog()
                {
                    //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                    Filter = "Excel files(2003) (*.xls)|*.xls",
                };
                if (downLoad.ShowDialog() == true)
                {
                    ss = downLoad.OpenFile();
                    PageInit();
                }
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("没有数据可以导出！");
                return;
            }
        }
        public void PageInit()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf.TextWrapRight = true;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf3 = xls.NewXF();
            xf3.UseBorder = true;
            xf3.TopLineStyle = 1;
            xf3.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.BottomLineStyle = 1;
            xf3.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.LeftLineStyle = 1;
            xf3.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.RightLineStyle = 1;
            xf3.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.HorizontalAlignment = HorizontalAlignments.Centered;
            xf3.VerticalAlignment = VerticalAlignments.Centered;
            xf3.Font.Bold = true;
            xf3.Font.Height = 12 * 20;

            Worksheet sheet1 = xls.Workbook.Worksheets.AddNamed("人员政审表");
            sheet1.Cells.Merge(1, 1, 1, 7);
            sheet1.Cells.Add(1, 1, "徐汇区" + (DateTime.Today.Year - nian.SelectedIndex).ToString() + "年招录人员政审表", xf1);
            sheet1.Cells.Add(2, 1, "序号", xf3);
            //sheet1.Cells.Add(2, 2, "名次", xf3);
            sheet1.Cells.Add(2, 2, "姓名", xf3);
            sheet1.Cells.Add(2, 3, "身份证号", xf3);
            sheet1.Cells.Add(2, 4, "报名单位", xf3);
            sheet1.Cells.Add(2, 5, "报名职务", xf3);
            sheet1.Cells.Add(2, 6, "政审结果", xf3);
            //sheet1.Cells.Add(2, 7, "笔试分数", xf3);
            //sheet1.Cells.Add(2, 8, "面试分数", xf3);
            //sheet1.Cells.Add(2, 9, "总分数", xf3);

            ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
            colInfoxueli1.Width = 15 * 256;
            colInfoxueli1.ColumnIndexStart = 2;
            colInfoxueli1.ColumnIndexEnd = 2;
            sheet1.AddColumnInfo(colInfoxueli1);

            ColumnInfo colInfoxueli2 = new ColumnInfo(xls, sheet1);
            colInfoxueli2.Width = 25 * 256;
            colInfoxueli2.ColumnIndexStart = 3;
            colInfoxueli2.ColumnIndexEnd = 3;
            sheet1.AddColumnInfo(colInfoxueli2);

            ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
            colInfoxueli3.Width = 20 * 256;
            colInfoxueli3.ColumnIndexStart = 4;
            colInfoxueli3.ColumnIndexEnd = 4;
            sheet1.AddColumnInfo(colInfoxueli3);

            for (int i = 0; i < selectedempmodel.Count; i++)
            {
                sheet1.Cells.Add(i + 3, 1, i + 1, xf);
                //sheet1.Cells.Add(i + 3, 2, selectedempmodel[i].MingCi.ToString(), xf);
                if (selectedempmodel[i].XingMing != null) sheet1.Cells.Add(i + 3, 2, selectedempmodel[i].XingMing.ToString(), xf);
                if (selectedempmodel[i].SFZH != null) sheet1.Cells.Add(i + 3, 3, selectedempmodel[i].SFZH.ToString(), xf);
                if (selectedempmodel[i].YRBM != null) sheet1.Cells.Add(i + 3, 4, selectedempmodel[i].YRBM.ToString(), xf);
                if (selectedempmodel[i].BBZW != null) sheet1.Cells.Add(i + 3, 5, selectedempmodel[i].BBZW.ToString(), xf);
                if (selectedempmodel[i].ZhengShenResult != null) sheet1.Cells.Add(i + 3, 6, selectedempmodel[i].ZhengShenResult.ToString(), xf);
            }
            xls.Save(ss);
            ss.Close();
            ss.Dispose();
            SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");
        }
        private string islock = "0";
        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            islock = "0";
            ObservableCollection<ZhaoLuJiHuaModel> poi1 = new ObservableCollection<ZhaoLuJiHuaModel>();
            poi1.Add(poi.Where(p => p.IsLocked == false).FirstOrDefault());
            nian.ItemsSource = poi1;
            if (poi1.Count > 0) nian.SelectedIndex = 0;
            Load();
        }
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            islock = "1";
            ObservableCollection<ZhaoLuJiHuaModel> poi1 = new ObservableCollection<ZhaoLuJiHuaModel>();
            foreach (ZhaoLuJiHuaModel i in poi)
            {
                if (i.IsLocked) poi1.Add(i);
            }
            nian.ItemsSource = poi1;
            if (poi1.Count > 0) nian.SelectedIndex = 0;
            Load();
        }
    }
}
